home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 669 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: gate.net!pslfl2-10
  2. From: bhutto@gate.net (William Hutto)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Problem with stringcopy
  5. Date: 8 Jan 1996 09:57:19 GMT
  6. Organization: CyberGate, Inc.
  7. Message-ID: <4cqppv$1quo@news.gate.net>
  8. References: <4clguu$9fs@eagle.novo.dk> <820933963snz@genesis.demon.co.uk> <4cq9dr$if9@ns.RezoNet.NET>
  9. NNTP-Posting-Host: pslfl2-10.gate.net
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. In article <4cq9dr$if9@ns.RezoNet.NET>,
  13.    ray@ultimate-tech.com (Ray Dunn) wrote:
  14. >In referenced article, Lawrence Kirby says...
  15. >>Morten Brun writes:
  16. >>
  17. >>>How do i do a partial stringcopy i.e. copy from a specific position 
  18. >>>in a string and a certain numbers of bytes. I am looking for a 
  19. >>>function like target = Stringcopy(source, startpos, length)
  20. >>
  21. >>target[0] = '\0';
  22. >>strncat(target, source+startpos, length);
  23. >
  24. >....but use strncpy if you are overwriting some existing characters in 
  25. >target and don't want the target string to terminate after the copied 
  26. >characters.
  27.  
  28. Considering strncpy()'s shortcomings, I amend my code:
  29.  
  30. char destination[ > max_length];
  31.  
  32.     strncpy(destination,&source[startpos],max_length);
  33.     destination[max_length]='\0';
  34.  
  35. Bill
  36.  
  37. "Whatcha got on?...Your mind?"
  38.